/*
 * @lc app=leetcode.cn id=2490 lang=cpp
 *
 * [2490] 回环句
 */

// @lc code=start
#include <bits/stdc++.h>
using namespace std;
class Solution
{
public:
    bool isCircularSentence(string sentence)
    {
        if ( (*(sentence.begin())) != (*(sentence.end()-1)) )
            return false;

        int space_inx = sentence.find_first_of(' ');
        while (space_inx < sentence.size())
        {
            if (sentence[space_inx - 1] != sentence[space_inx + 1])
                return false;
            space_inx = sentence.find(' ', space_inx + 1);
        }
        return true;
    }
};
// int main(int argc, char const *argv[])
// {
//     cout << Solution().isCircularSentence("leetcode exercises sound delightful") << endl;
//     return 0;
// }

// @lc code=end
